﻿namespace MyWebLog.Logic.Models
{
    using DatabaseAbstraction.Interfaces;
    using System.Collections.Generic;
    using System.Data;

    /// <summary>
    /// This represents a blog, an entity with posts and pages
    /// </summary>
    public class Blog : IParameterProvider
    {
        #region Properties

        /// <summary>
        /// The ID of this blog
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// The name of the blog
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// The subtitle/description for the blog
        /// </summary>
        public string Subtitle { get; set; }

        /// <summary>
        /// The base URL for the blog
        /// </summary>
        public string BaseURL { get; set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Constructor (empty object)
        /// </summary>
        public Blog() { }

        /// <summary>
        /// Constructor (filled object)
        /// </summary>
        /// <param name="reader">
        /// An open data reader, pointing to the row to use
        /// </param>
        public Blog(IDataReader reader)
        {
            ID = reader.GetInt32(reader.GetOrdinal("blog_id"));
            Name = reader.GetString(reader.GetOrdinal("blog_name"));
            Subtitle = reader.GetString(reader.GetOrdinal("subtitle"));
            BaseURL = reader.GetString(reader.GetOrdinal("base_url"));
        }

        #endregion

        #region Interface Implementation

        /// <summary>
        /// This object's properties as a dictionary, for use in persistence
        /// </summary>
        /// <returns>
        /// A key/value dictionary of the properties of this object
        /// </returns>
        public IDictionary<string, object> Parameters()
        {
            var parameters = new Dictionary<string, object>();

            parameters.Add("blog_id", ID);
            parameters.Add("blog_name", Name);
            parameters.Add("subtitle", Subtitle);
            parameters.Add("base_url", BaseURL);

            return parameters;
        }

        #endregion
    }
}